import { Component, Vue, Inject } from 'vue-property-decorator';

import { IRoomUserBrokerChatList } from '@/shared/model/room-user-broker-chat-list.model';
import RoomUserBrokerChatListService from './room-user-broker-chat-list.service';
import AlertService from '@/shared/alert/alert.service';

@Component
export default class RoomUserBrokerChatListDetails extends Vue {
  @Inject('roomUserBrokerChatListService') private roomUserBrokerChatListService: () => RoomUserBrokerChatListService;
  @Inject('alertService') private alertService: () => AlertService;

  public roomUserBrokerChatList: IRoomUserBrokerChatList = {};

  beforeRouteEnter(to, from, next) {
    next(vm => {
      if (to.params.roomUserBrokerChatListId) {
        vm.retrieveRoomUserBrokerChatList(to.params.roomUserBrokerChatListId);
      }
    });
  }

  public retrieveRoomUserBrokerChatList(roomUserBrokerChatListId) {
    this.roomUserBrokerChatListService()
      .find(roomUserBrokerChatListId)
      .then(res => {
        this.roomUserBrokerChatList = res;
      })
      .catch(error => {
        this.alertService().showHttpError(this, error.response);
      });
  }

  public previousState() {
    this.$router.go(-1);
  }
}
